package com.middlegroup.pay.web.api;

import com.middlegroup.common.model.*;
import com.middlegroup.pay.bind.SessionMerchantCode;
import com.middlegroup.pay.bind.SessionSubjectCode;
import com.middlegroup.pay.service.SubjectPayService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 *协议支付
 * @author pc
 * @date 2019/1/15
 */
@RestController
public class ProtocolPayController extends BaseController {

    @Resource
    private SubjectPayService subjectPayService;


    /**绑卡接口
     * @param bindCardDto
     * @return
     */
    @RequestMapping("bindCard")
    public ResponseEntity bindCard(@Valid BindCardDto bindCardDto, @SessionSubjectCode String subjectCode, @SessionMerchantCode String merchantCode){
        bindCardDto.setMerchantCode(merchantCode);
        bindCardDto.setSubjectCode(subjectCode);
        TransResult result = subjectPayService.bindCard(bindCardDto);
        return new ResponseEntity(ResponseEntity.STATUS_OK,result);
    }

    /**协议支付支付
     * @param request
     * @return
     */
    @RequestMapping("protocolPay")
    public ResponseEntity protocolPay(@Valid TransRequest request,@SessionMerchantCode String merchantCode,@SessionSubjectCode String subjectCode){
        request.setSubjectCode(subjectCode);
        request.setMerchantCode(merchantCode);
        if (null == request.getStep()){
            return new ResponseEntity(ResponseEntity.STATUS_FAIL,null,"协议支付步骤不能为空!",null);
        }
        return new ResponseEntity(ResponseEntity.STATUS_OK,subjectPayService.protocolPay(request));
    }
}
